const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('sp_attribute', {
    attr_id: {
      autoIncrement: true,
      type: DataTypes.SMALLINT.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: "主键id"
    },
    attr_name: {
      type: DataTypes.STRING(32),
      allowNull: false,
      comment: "属性名称"
    },
    cat_id: {
      type: DataTypes.SMALLINT.UNSIGNED,
      allowNull: false,
      comment: "外键，类型id"
    },
    attr_sel: {
      type: DataTypes.ENUM('only','many'),
      allowNull: false,
      defaultValue: "only",
      comment: "only:输入框(唯一)  many:后台下拉列表\/前台单选框"
    },
    attr_write: {
      type: DataTypes.ENUM('manual','list'),
      allowNull: false,
      defaultValue: "manual",
      comment: "manual:手工录入  list:从列表选择"
    },
    attr_vals: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "可选值列表信息,例如颜色：白色,红色,绿色,多个可选值通过逗号分隔"
    },
    delete_time: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "删除时间标志"
    }
  }, {
    sequelize,
    tableName: 'sp_attribute',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "attr_id" },
        ]
      },
      {
        name: "type_id",
        using: "BTREE",
        fields: [
          { name: "cat_id" },
        ]
      },
    ]
  });
};
